package com.ruoyi.lock.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.lock.domain.ALogs;
import com.ruoyi.lock.service.IALogsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 开锁日志表Controller
 * 
 * @author ruoyi
 * @date 2024-08-05
 */
@RestController
@RequestMapping("/lock/logs")
public class ALogsController extends BaseController
{
    @Autowired
    private IALogsService aLogsService;

    /**
     * 查询开锁日志表列表
     */
    @PreAuthorize("@ss.hasPermi('lock:logs:list')")
    @GetMapping("/list")
    public TableDataInfo list(ALogs aLogs)
    {
        startPage();
        List<ALogs> list = aLogsService.selectALogsList(aLogs);
        return getDataTable(list);
    }

    /**
     * 导出开锁日志表列表
     */
    @PreAuthorize("@ss.hasPermi('lock:logs:export')")
    @Log(title = "开锁日志表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ALogs aLogs)
    {
        List<ALogs> list = aLogsService.selectALogsList(aLogs);
        ExcelUtil<ALogs> util = new ExcelUtil<ALogs>(ALogs.class);
        util.exportExcel(response, list, "开锁日志表数据");
    }

    /**
     * 获取开锁日志表详细信息
     */
    @PreAuthorize("@ss.hasPermi('lock:logs:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(aLogsService.selectALogsById(id));
    }

    /**
     * 新增开锁日志表
     */
    @PreAuthorize("@ss.hasPermi('lock:logs:add')")
    @Log(title = "开锁日志表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ALogs aLogs)
    {
        return toAjax(aLogsService.insertALogs(aLogs));
    }

    /**
     * 修改开锁日志表
     */
    @PreAuthorize("@ss.hasPermi('lock:logs:edit')")
    @Log(title = "开锁日志表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ALogs aLogs)
    {
        return toAjax(aLogsService.updateALogs(aLogs));
    }

    /**
     * 删除开锁日志表
     */
    @PreAuthorize("@ss.hasPermi('lock:logs:remove')")
    @Log(title = "开锁日志表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aLogsService.deleteALogsByIds(ids));
    }
}
